Uec3.Dictionary=Ext.extend(Ext.util.Observable,{
	constructor:function(config){
		Ext.apply(this, config);
		//this.items=new Ext.util.MixedCollection(false);
        this.init();
        Uec3.Dictionary.superclass.constructor.call(this);
	},
	data:new Ext.util.MixedCollection(false),
	init:function(){
		//this.data.on("add",)
	},
	getStore:function(group,config){
		var url=Uec3.App.Constants.homeUrl+'/dictionary/findByVarGroupRoot.do';
		var retstore=new Ext.data.JsonStore({
			url : url,
			root : 'root',
			baseParams:{'group':group},
			fields : [
				{name : 'varIndex',type : 'int'}, 
				{name : 'varName',type : 'string'}]
		});
		if(Ext.isFunction(config.callBack)){
			restore.on("load",config.callBack);
		}
		if(!this.data.get(group)){
			retstore.on("load",function(store, records, options){
				if(!this.data.get(group)){
					this.data.add(group,this.addRecordsToData(records));
				}
				this.addWholeSelect(store,config);

			},this);
			retstore.load();
		}else{
			retstore.loadData(this.data.get(group));
			retstore.fireEvent("load",retstore,retstore.getRange(),{'group':group});
			this.addWholeSelect(retstore,config);	
		}
		return retstore;
	},
	addRecordsToData:function(records){
		var item=[];
		var ret={};
		Ext.each(records,function(record){
			item.push(record.data);
		});
		ret.root=item;
		return ret;
	},
	addWholeSelect:function(store,config){
		if(config.showWhole===true){
			store.insert(0, new Ext.data.Record({ 'varIndex': null, 'varName': '请选择' }, '-1'));
		}else if(config.showBlank===true){
			store.insert(0, new Ext.data.Record({ 'varIndex': null, 'varName': '全部' }, '99999'));
		}
	},
	getCombo:function(group,config){
		var store;
		if(config&&config.store){
			store=config.store;
		}else{
			store=this.getStore(group,config);
		}
		var defaultConfig={
			typeAhead : true,
			width : 150,
			valueField : 'varIndex',
			displayField : 'varName',
			mode : 'local',
			// hiddenName : 'source',
			store : store,
			selectOnFocus : true,
			forceSelection : true,
			triggerAction : 'all',
			allowBlank : true,
			loadingText : '加载中...',
			editable : false,
			emptyText : '请选择...'
		};
		config=Ext.apply(defaultConfig,config);
		var dictionary_comboBox = new Ext.form.ComboBox(config);
		return dictionary_comboBox;
	}
	
});
Uec3.App.dictionary=new Uec3.Dictionary();
